package com.hao.eduservice.controller;


import com.hao.commonutils.R;
import com.hao.eduservice.entity.subject.OneSubject;
import com.hao.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author hao
 * @since 2020-11-30
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;


    /**
     * 通过读取上传的excel，添加课程分类
     *
     * @param file 文件
     * @return {@link R}
     */
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }

    @GetMapping("getAllSubject")
    public R getAllSubject(){

        List<OneSubject> list = subjectService.getAllSubject();
        return R.ok().data("list",list);
    }
}

